package com.ptt.sqm.session;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.content.SharedPreferences;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ptt.sqm.util.AppUtil;

public class SavedItemAssess {
	 // Context
    Context _context;
    private static SharedPreferences prefs;	 
	private static final Type MAP_TYPE = new TypeToken<HashMap<String, String>>() {}.getType();

	private static Map<String, String> myMap;

	
	public SavedItemAssess(Context _context) {
		super();
		this._context = _context;
		prefs = _context.getSharedPreferences(AppUtil.SAVED_ITEM_ASSESS_PREF, Context.MODE_PRIVATE);
	}

	public static void saveMap (String projCycleId, Map<String, String> map) {
	    SharedPreferences.Editor editor = prefs.edit();

	    editor.putString(projCycleId, new Gson().toJson(map));
	    editor.commit();
	    myMap = map;
	}

	public static Map<String, String> loadMap(String projCycleId) {		
	    myMap = new Gson().fromJson(prefs.getString(projCycleId, null), MAP_TYPE);	   
	    if(myMap == null) {
	    	myMap = new HashMap<String, String>();
	    }
	    return myMap;
	}       
	
	public static void ClearSavedItem() {
		SharedPreferences.Editor editor = prefs.edit();
		editor.clear();
        editor.commit();
	}

}
